package toDo.app;

import interfaces.IRegisterActivity;
import toDo.app.controllers.RegisterActivityClickController;
import toDo.app.controllers.TextMatcher;
import android.os.Bundle;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class RegisterActivity extends IRegisterActivity{
	/**
	 * put all the buttons and fields as private things, easier to work with
	 */
	private EditText usernameField;
	private EditText passwordField;
	private EditText passwordConfirmField;
	private Button backButton;
	private Button registerButton;
	private TextView statusLabel;
	private TextMatcher textMatcher;
	private RegisterActivityClickController cController;
	
	/**
	 * registration screen
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.register);
		// create all of buttons and fields
		usernameField = (EditText) findViewById(R.id.registerUsernameField);
		passwordField = (EditText) findViewById(R.id.registerPasswordField);
		passwordConfirmField = (EditText) findViewById(R.id.registerPasswordConfirmField);
		backButton = (Button) findViewById(R.id.registerBackButton);
		registerButton = (Button) findViewById(R.id.registerRegisterButton);
		statusLabel = (TextView) findViewById(R.id.registerStatusLabel);

		textMatcher = new TextMatcher(passwordField, passwordConfirmField).setStatusLabel(statusLabel)
				.setResultEnable(registerButton)
				.setString(getString(R.string.blank), getString(R.string.passwordMatch));
		passwordField.addTextChangedListener(textMatcher);
		passwordConfirmField.addTextChangedListener(textMatcher);
		cController = new RegisterActivityClickController(this);
		
		registerButton.setOnClickListener(cController);
		backButton.setOnClickListener(cController);
		statusLabel.setText(R.string.blank);
	}

	@Override
	public String getUsername() {
		return usernameField.getText().toString();
	}

	@Override
	public String getPassword() {
		return passwordConfirmField.getText().toString();
	}

	@Override
	public void setStatusLabelText(String text) {
		statusLabel.setText(text);
	}
}
